<template>
  <div id="app">
    <el-container class="layout-container">
      <!-- 顶部导航栏 -->
      <el-header class="header">
        <div class="header-content">
          <div class="logo">
            <h1>Tete1 Git同步系统</h1>
          </div>
          <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
          >
            <el-menu-item index="/dashboard">
              <el-icon><Monitor /></el-icon>
              <span>控制台</span>
            </el-menu-item>
            <el-menu-item index="/tasks">
              <el-icon><List /></el-icon>
              <span>任务管理</span>
            </el-menu-item>
            <el-menu-item index="/repositories">
              <el-icon><Folder /></el-icon>
              <span>代码库管理</span>
            </el-menu-item>
            <el-menu-item index="/executions">
              <el-icon><Clock /></el-icon>
              <span>执行记录</span>
            </el-menu-item>
            <el-menu-item index="/logs">
              <el-icon><Document /></el-icon>
              <span>日志管理</span>
            </el-menu-item>
            <el-menu-item index="/files">
              <el-icon><Files /></el-icon>
              <span>文件管理</span>
            </el-menu-item>
            <el-menu-item index="/settings">
              <el-icon><Setting /></el-icon>
              <span>系统设置</span>
            </el-menu-item>
          </el-menu>
        </div>
      </el-header>

      <!-- 主要内容区域 -->
      <el-main class="main-content">
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

const activeIndex = computed(() => route.path)

const handleSelect = (key) => {
  console.log('导航到:', key)
  router.push(key).catch(err => {
    console.error('路由跳转失败:', err)
  })
}

// 添加全局错误处理
onMounted(() => {
  console.log('App.vue 已挂载')
  console.log('当前路由:', route.path)

  // 添加全局错误监听
  window.addEventListener('error', (event) => {
    console.error('全局错误:', event.error)
  })

  // 添加未处理的Promise拒绝监听
  window.addEventListener('unhandledrejection', (event) => {
    console.error('未处理的Promise拒绝:', event.reason)
  })
})
</script>

<style scoped>
.layout-container {
  height: 100vh;
}

.header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  padding: 0;
}

.header-content {
  display: flex;
  align-items: center;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

.logo {
  margin-right: 40px;
}

.logo h1 {
  color: #409eff;
  font-size: 20px;
  margin: 0;
}

.el-menu-demo {
  border-bottom: none;
  flex: 1;
}

.main-content {
  background-color: #f5f7fa;
  padding: 20px;
}

#app {
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
}
</style>